// 引入 express 框架
const express = require('express')
const app = express()
const cors = require('cors')
const bodyParser = require('body-parser')
const router = require("./routers/index");
const path = require("path")
const fs = require("fs")
// const http = require("http")
const https = require("https")


// 引入 ssl 证书
const httpsOption = {
  key : fs.readFileSync("../https/5026783_webpti.cn.key"),
  cert: fs.readFileSync("../https/5026783_webpti.cn.pem")
}


// 配置post请求
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// 静态资源目录
app.use(express.static(path.resolve("./public")));
// 开启跨域设置
app.use(cors())

// 将路由引入
app.use(router);

// 监听 5210 端口
// http.createServer(app).listen(5210, () => { console.log('服务启动成功')});
// 监听 https 协议的端口号
https.createServer(httpsOption, app).listen(5210, () => { console.log('https://localoshot:5210')});